package in.ac.dei.edrp.cms.daoimpl.prestaging;

import in.ac.dei.edrp.cms.dao.prestaging.PrestagingService;
import in.ac.dei.edrp.cms.domain.coursegroup.CourseGroupBean;
import in.ac.dei.edrp.cms.domain.coursemaster.CourseMasterBean;
import in.ac.dei.edrp.cms.domain.registration.prestaging.TransferPSTRDYInSTBean;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class PrestagingServiceImpl extends SqlMapClientDaoSupport implements
		PrestagingService {

	/** Creating object of Logger for log Maintenance */
	private static Logger logObj = Logger
			.getLogger(PrestagingServiceImpl.class);

	@SuppressWarnings("unchecked")
	public List<CourseMasterBean> getChildEntityList(
			CourseGroupBean prestagingInfoGetter) {
		List<CourseMasterBean> dataList = new ArrayList<CourseMasterBean>();
		try {
			dataList = getSqlMapClientTemplate().queryForList(
					"prestagingData.getChildEntity", prestagingInfoGetter);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return dataList;
	}

	@SuppressWarnings("unchecked")
	public List<CourseMasterBean> getProgramList(String entityId) {
		List<CourseMasterBean> dataList = new ArrayList<CourseMasterBean>();
		try {
			dataList = getSqlMapClientTemplate().queryForList(
					"prestagingData.getEntityProgram", entityId);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return dataList;
	}

	@SuppressWarnings("unchecked")
	public List<CourseMasterBean> getBranchList(
			CourseGroupBean prestagingInfoGetter) {
		List<CourseMasterBean> dataList = new ArrayList<CourseMasterBean>();
		try {
			dataList = getSqlMapClientTemplate().queryForList(
					"prestagingData.getEntityProgramBranch",
					prestagingInfoGetter);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return dataList;
	}

	@SuppressWarnings("unchecked")
	public List<CourseMasterBean> getSpecializationList(
			CourseGroupBean prestagingInfoGetter) {
		List<CourseMasterBean> dataList = new ArrayList<CourseMasterBean>();
		try {
			dataList = getSqlMapClientTemplate().queryForList(
					"prestagingData.getEntityProgramBranchSpecialization",
					prestagingInfoGetter);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return dataList;
	}

	public List<TransferPSTRDYInSTBean> setPrestagingData(
			List<TransferPSTRDYInSTBean> inputPrestagingData) {
		List<TransferPSTRDYInSTBean> insertedData = new ArrayList<TransferPSTRDYInSTBean>();
		for (int i = 0; i < inputPrestagingData.size(); i++) {
			try {
				TransferPSTRDYInSTBean inputRow = inputPrestagingData.get(i);
				getSqlMapClientTemplate().insert(
						"prestagingData.insertDataIntoPreStaging",
						inputRow);
				insertedData.add(inputRow);
			} catch (Exception e) {
				logObj.error(e.getMessage());
			}
		}
		return insertedData;
	}

	@SuppressWarnings("unchecked")
	public String getRegistrationDueDate(TransferPSTRDYInSTBean inputBean) {
		List<TransferPSTRDYInSTBean> dataList = new ArrayList<TransferPSTRDYInSTBean>();
		String s="";
		try {
			dataList = getSqlMapClientTemplate().queryForList(
					"prestagingData.getRegistrationDueDate", inputBean);
			if(dataList.size()>0)
			{
				s=dataList.get(0).getRegisterDueDate();
			}
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return s;
	}

}
